#ifndef NODE_H
#define NODE_H

#include <QString>
#include <QList>
#include <QPair>

#include "base.h"
#include "nodetypes.h"

class Node : public JObject
{
public:
    Node(Node *parent = nullptr) :
        JObject(parent)
    {
        // Check the parent.
        if(parent)
        {
            // Recast the parent node.
            parent->node_add(this);
        }
    }

    virtual ~Node() {}

    virtual NodeTaskList tasks() const = 0;

    void node_add(Node *node)
    {
        //Add node to children list.
        __children.append(node);
    }

    NodeTaskInfoList all_tasks()
    {
        // Prepare the task list.
        NodeTaskInfoList task_list;
        // Get the task list of current node.
        NodeTaskList node_task_list = tasks();
        if(node_task_list.size() > 0)
        {
            // Add current node and task list.
            task_list.append(NodeTaskInfo(this, node_task_list));
        }
        // Add all the children tasks to task list.
        for(Node *node : __children)
        {
            NodeTaskInfoList child_task_list = node->all_tasks();
            // Check child list.
            if(child_task_list.size() > 0)
            {
                //Append the data to task list.
                task_list.append(child_task_list);
            }
        }
        // Return the task list.
        return task_list;
    }

private:
    QString __name;
    QList<Node *> __children;
};

class TopModule : public Node
{
public:
    TopModule() :
        Node(nullptr)
    {
    }

    NodeTaskList tasks() const override
    {
        NodeTaskList list;
        return list;
    }
};

#endif // NODE_H
